<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      https://leetcode-cn.com/problems/min-stack/
      思路：https://leetcode-cn.com/problems/min-stack/solution/zui-xiao-zhan-by-leetcode-solution/
     */
    
    /**
     * initialize your data structure here.
     */
    var MinStack = function () {
      this.x_stack = [];
      this.min_stack = [Infinity];
    };

    /** 
     * @param {number} x
     * @return {void}
     */
    MinStack.prototype.push = function (x) {
      this.x_stack.push(x);
      this.min_stack.push(Math.min(x, this.min_stack[this.min_stack.length - 1]))
    };

    /**
     * @return {void}
     */
    MinStack.prototype.pop = function () {
      this.x_stack.pop();
      this.min_stack.pop();
    };

    /**
     * @return {number}
     */
    MinStack.prototype.top = function () {
      return this.x_stack[this.x_stack.length - 1]
    };

    /**
     * @return {number}
     */
    MinStack.prototype.getMin = function () {
      return this.min_stack[this.min_stack.length - 1]
    };

    /**
     * Your MinStack object will be instantiated and called as such:
     * var obj = new MinStack()
     * obj.push(x)
     * obj.pop()
     * var param_3 = obj.top()
     * var param_4 = obj.getMin()
     */
  </script>
</body>
</html>